#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n;
struct node
{
	int a,b;
	bool operator<(const node &a)const{return b>a.b;}
}a[114514];
int mn,cmn,ans;
signed main()
{
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i].a=read(),a[i].b=read();
	sort(a+1,a+n+1);
	mn=min(a[1].a+a[1].b,a[2].a+a[2].b);
	cmn=max(a[1].a+a[1].b,a[2].a+a[2].b);
	ans=1e18;
	for(int i=3;i<=n;i++)
	{
		ans=min(ans,a[i].a+mn+cmn);
		if(a[i].a+a[i].b<=mn) cmn=mn,mn=a[i].a+a[i].b;
		else cmn=min(cmn,a[i].a+a[i].b);
	}
	write(ans);
	return 0;
}

